package com.wecheir.service.impl;

import com.wecheir.dao.UserDao;
import com.wecheir.entity.User;
import com.wecheir.service.UserService;
import com.wecheir.utils.ResponseUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {


    @Resource
    UserDao userDao;

    public void register(){



    }


    @Override
    public void updateUserOnlyCredit(User user) {

    }

    @Override
    public String findFarmOwnManagerIdById(String id) {
        return null;
    }

    @Override
    public User findUserByLoginName(String name) {
        return null;
    }

    @Override
    public User findUserById(String id) {
        return userDao.findUserById(id);
    }

    @Override
    public int userCount(String loginName) {
        return 0;
    }

    @Override
    public void saveUser(User user) {

    }

    @Override
    public void updateUser(User user) {

    }

    @Override
    public void deleteUser(User user) {

    }

    @Override
    public void lockUser(User user) {

    }

    @Override
    public List<User> findAllUser() {
        return null;
    }

    @Override
    public User selectUserByTellOrEmail(String tel, String email) {
        System.out.println(tel + email);
        return userDao.selectUserByTellOrEmail(tel,email);
    }

    @Override
    public List<User> getAllHaveManagerIdentityUser() {
        return null;
    }

    @Override
    public int resetCredit(User user) {
        return 0;
    }

    @Override
    public ResponseUtils checkUser(User userParam, User user) {
        if (null==user){
            return ResponseUtils.setFailure("属性值不正确,没有该用户!");
        }
        if (user.getCredit() < 0.3){
            return ResponseUtils.setFailure("信誉值不足，不能访问!");
        }
        if (userParam.getPassword().equals(user.getPassword())){
            return ResponseUtils.setFailure("密码错误!");
        }
        if (user.getLocked() == 1){
            return ResponseUtils.setFailure("账户已被锁定!");
        }
        if (user.getIs_admin() == 0){
            return ResponseUtils.setFailure("账户不是管理用户!");
        }

        return ResponseUtils.setSuccess(user);
    }
}
